class xT_AICommand_Cmd_CheckNoise extends xT_AICommand_Cmd;

//=============================================================================
// Variables
//=============================================================================
var private xT_Pawn         PossibleEnemy;
var private int             ChekCount;

//=============================================================================
// Events
//=============================================================================
event Popped()
{
	StopLatentExecution();
	SetDesiredRotation(Pawn.Rotation);
}

//=============================================================================
// State
//=============================================================================
AUTO state CheckingNoise
{

	function LookAround() 
	{ 
	 	local Rotator lnewRotation; 
	 	if (Pawn != none) 
	 	{ 
	 		lnewRotation = RotRand(false); 
	 		ClampRotation(lnewRotation, lnewRotation, Rot(0,0,0), Rot(0,4096,0)); 
	 		lnewRotation.Pitch = Pawn.Rotation.Pitch; 
	 		lnewRotation.Roll = Pawn.Rotation.Roll; 
	 		SetDesiredRotation(lnewRotation); 
	 	}                
	}
	
Begin:
	//`log("xT_AICommand_CheckNoise executed");

Prepare:
	if (PossibleEnemy == none)
	{
		Sleep(WorldInfo.DeltaSeconds);
		Goto('Prepare');
	}	

Checking:
	Pawn.FaceRotation(Rotator(location - PossibleEnemy.location), WorldInfo.DeltaSeconds * 3);
	FinishRotation();
	Sleep(WorldInfo.DeltaSeconds* 10); // make chance pawn will see enemy

Moving:
	xT_AIController(Outer).MoveToPosition(PossibleEnemy.location, true, true);

LookAround:
	Sleep(WorldInfo.DeltaSeconds);
	LookAround();
	FinishRotation();
	Sleep(FRand()*100);
	ChekCount++;
	if (ChekCount<3) Goto('LookAround');

End:
	PopCommand(self);
}

//=============================================================================
// State
//=============================================================================
function SetPossibleEnemy(xT_Pawn aPossibleEnemy)
{
	PossibleEnemy = aPossibleEnemy;
}

//=============================================================================
// Reaction on sensors
//=============================================================================
public function Reaction_SeeEnemy(xT_Pawn aEnemy)
{
	PopCommand(self);
}

//=============================================================================
// DefaultProperties
//=============================================================================
defaultproperties
{
}
